package com.rh.controller;

import com.rh.result.ResultVo;
import com.rh.service.VodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/eduvod/video")
@Api(tags = "阿里云视频点播")
@CrossOrigin
public class VodController {
    @Autowired
    private VodService vodService;
    /**
     * 上传视频到阿里云
     */
    @ApiOperation(value = "1.上传视频到阿里云")
    @PostMapping("uploadAlyiVideo")
    public ResultVo uploadAlyiVideo(MultipartFile file){
        //返回上传视频的id
        String videoId=vodService.uploadVideoAly(file);
        return ResultVo.ok().data("videoId",videoId);
    }
    /**
     * 根据视频id删除阿里云中的视频
     */
    @ApiOperation(value = "2.根据视频id删除阿里云中的视频")
    @DeleteMapping("removeAlyVideo/{id}")
    public ResultVo removeAlyVideo(@PathVariable String id){
        vodService.removeVideo(id);
        return ResultVo.ok();
    }
    /**
     * 一个章节下可能有多个视频，因此开一个删除多个视频的接口
     */
    @ApiOperation(value = "3.删除多个阿里云视频")
    @DeleteMapping("delete-batch")
    public ResultVo deleteBatchVideo(@RequestParam("videoIdList") List<String> videoIdList){
        vodService.removeManyAlyVideo(videoIdList);
        return ResultVo.ok();
    }
    /**
     * 根据视频id获取视频播放凭证
     */
    @ApiOperation(value = "4.根据视频id获取播放凭证")
    @GetMapping("getPlayAuth/{id}")
    public ResultVo getPlayAuth(@PathVariable String id){
        String playAuth=vodService.getAuth(id);
        System.out.println("播放凭证:"+playAuth);
        return ResultVo.ok().data("playAuth",playAuth);
    }
}
